package com.ftg.learn.controller;

import com.ftg.learn.entity.Product;
import com.ftg.learn.service.IProductService;
import com.ftg.learn.util.PageEx;
import com.ftg.learn.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;


/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 布衣
 * @since 2025-07-22
 */
@RestController
@RequestMapping("/product")
@Tag(name = "商品管理")
public class ProductController {

    @Resource
    private IProductService productService;

    @GetMapping("/list")
    @Operation(description="商品列表")
    public R<String> list(
           @Param("name") @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "page") Integer page,
            @RequestParam(value = "size") Integer size
    ) {
        return productService.list(name, page, size);
    }

    /**
     * 图片上传功能实现
     *
     * @param product 商品
     * @return
     */
    @PostMapping("/add")
    @Operation(description = "添加商品")
    public R<Boolean> add(@RequestBody Product product) {
        return R.ok(productService.save(product));
    }

    @PutMapping("/update/{id}")
    @Operation(description = "修改商品")
    public R<String> update(@PathVariable("id") Integer id, @RequestBody Product product) {
        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    @Operation(description = "删除商品")
    public R<String> delete(@PathVariable("id") Integer id) {
        return R.ok();
    }


}
